﻿using System.Linq;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace MyAnt
{
	public static class RoleEnvironmentChangingEventArgsExtensions
	{
		public static bool TryGetChangedSetting(this RoleEnvironmentChangingEventArgs roleEnvironmentChangingEventArgs, string key, out string value)
		{
			value = null;
			if (roleEnvironmentChangingEventArgs.Changes
																					.Where(change => change is RoleEnvironmentConfigurationSettingChange)
																					.Cast<RoleEnvironmentConfigurationSettingChange>()
																					.FirstOrDefault(change => change.ConfigurationSettingName == key) != null)
			{
				value = RoleEnvironment.GetConfigurationSettingValue(key);
			}
			return value != null;
		}
	}
}